// hash_string.rs

/// Generate a hash key from a string.
///
/// # Arguments
///
/// * `string` - The string.
///
/// # Returns
///
/// A hash key for the string.
pub fn string_hash(string: &str) -> u32 {
    // This is the djb2 string hash function
    let mut result = 5381u32;
    for byte in string.as_bytes() {
        result = (result << 5).wrapping_add(result).wrapping_add(*byte as u32);
    }
    result
}

/// Generate a hash key from a string, ignoring the case of letters.
///
/// # Arguments
///
/// * `string` - The string.
///
/// # Returns
///
/// A hash key for the string.
pub fn string_nocase_hash(string: &str) -> u32 {
    let mut result = 5381u32;
    for byte in string.as_bytes() {
        result = (result << 5)
            .wrapping_add(result)
            .wrapping_add(byte.to_ascii_lowercase() as u32);
    }
    result
}
